import { View } from "../../../mvc/core/View";
import { LayerManager } from "../../manager/LayerManager";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { ItemsBox } from "../common/item/ItemsBox";
import { PetProcessBar } from "../pet/PetProcessBar";
import { GlobalSkin } from "../../../component/skin/GlobalSkin";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { EntityInfo } from "../../scene/player/info/EntityInfo";
import { TBoss } from "../../../../Message/Db/Tables/TBoss";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { Tooltip } from "../common/tooltip/Tooltip";
import { PlantFlowerBlessCache } from "./PlantFlowerBlessCache";
import { PlantFlowerConfig } from "../../resource/PlantFlowerConfig";
import { GameConst } from "../../../component/gconst/GameConst";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { TimeButton } from "../common/button/TimeButton";
type int = number;
//class PlantLightBlessWindow
    
    export  class PlantLightBlessWindow extends View
    {
        constructor()
        {
            super();
            this.layer = LayerManager.windowLayer;
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            this.addChild(new GImageBitmap(ImagesConst.PlantLightWinBg, 0, 0));
            this._closeBtn = ObjCreate.createGButton("", 383, 22, 19, 19, this, "CloseButton");
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.closeBtnClickHandler);
            var loc1=GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6);
            loc1.size = 14;
            loc1.bold = true;
            this._nameLabel = ObjCreate.createGTextField("", 80, 74, 335, 20, this, loc1);
            loc1.size = 12;
            loc1.color = 16776960;
            loc1.align = flash.text.TextFormatAlign.LEFT;
            ObjCreate.createGTextField(Language.getString(69828) + ":", 121, 188, 200, 20, this, loc1);
            this._itemsList = new ItemsBox();
            this._itemsList.x = 144;
            this._itemsList.y = 134;
            this.addChild(this._itemsList);
            this._progressBar = new PetProcessBar(ImagesConst.GreenBar10, 166, 12);
            this._progressBar.move(188, 192);
            this._progressBar.setValue(0, 0);
            addChild(this._progressBar);
            this._operBtn = ObjCreate.createTimeButton("", 215, 216, 70, 22, this, GlobalSkin.ButtonRed);
            this._operBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOperBtnClickHandler);
            this._tip = ObjCreate.createGTextField(HTMLUtil.addColor(Language.getString(69816), "#106203"), 150, 242, 220, 20, this);
            this._tip.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tip.filters = [];
            return;
        }

        protected closeBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            hide();
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            LoaderManager.instance.load(ImagesConst.PlantLightWinBg + ".swf", this.preloaded);
            return;
        }

        /* internal  */preloaded(arg1): void
        {
            super.show(x, y);
            if (_layer) 
            {
                _layer.centerPopup(this);
            }
            return;
        }

        public updateFlowerInfo(arg1: EntityInfo, arg2: TBoss): void
        {
            var loc1=0;
            this._info = arg1;
            this._bossInfo = arg2;
            this._isMine = arg1.isSelf;
            this._canGet = arg1.entityInfo.mana == 0;
            this._nameLabel.htmlText = Language.getStringByParam(69827, arg1.entityInfo.guildName, arg1.entityInfo.name);
            this._progressBar.setValue(arg1.entityInfo.maxMana - arg1.entityInfo.mana, arg1.entityInfo.maxMana);
            this._operBtn.clearCountDown();
            if (this._isMine) 
            {
                this._operBtn.enabled = true;
                if (this._canGet) 
                {
                    this._operBtn.timeCount = 3;
                    this._operBtn.label = Language.getString(69833);
                    this._operBtn.toolTipData = "";
                }
                else 
                {
                    this._operBtn.timeCount = 60;
                    this._operBtn.label = Language.getString(69814);
                    this._operBtn.toolTipData = new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, HTMLUtil.addColor(Language.getString(69835), "#FFFFFF"));
                    loc1 = PlantFlowerBlessCache.getInviteCd();
                    if (loc1 > 0) 
                    {
                        this._operBtn.trigger();
                        this._operBtn.repeatCount = loc1;
                    }
                }
                this._itemsList.setItems(PlantFlowerConfig.instance.getPlantAward(arg1.entityInfo.code));
                this._tip.visible = false;
            }
            else 
            {
                this._itemsList.setItems(PlantFlowerConfig.instance.getBlessAward(arg1.entityInfo.code));
                this._operBtn.timeCount = 3;
                this._operBtn.label = Language.getString(69815);
                this._operBtn.toolTipData = new ToolTipInfo(Tooltip.ToolTipRenderType_ShortcutItem, HTMLUtil.addColor(Language.getStringByParam(69834, this._itemsList.getItemNameByIndex(0), this._itemsList.getItemNameByIndex(1), this._itemsList.getItemNameByIndex(2)), "#FFFFFF"));
                this._tip.visible = true;
                this._tip.htmlText = HTMLUtil.addColor(Language.getStringByParam(69816, GameConst.PlantFlowerBlessRewardLimit) + " (" + Cache.instance.plantFlower.hasBlessTimes + "/" + GameConst.PlantFlowerBlessRewardLimit + ")", "#106203");
                if (this._canGet || PlantFlowerBlessCache.hasBless(arg1.entityInfo.entityId)) 
                {
                    this._operBtn.enabled = false;
                }
                else 
                {
                    this._operBtn.enabled = true;
                }
            }
            return;
        }

        /* internal  */onOperBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._isMine) 
            {
                if (this._canGet) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlantFlower_GetFlower, this._info));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PlantFlower_InviteBless, this._info));
                }
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PlantFlower_DoBless, this._info));
                this.hide();
            }
            return;
        }

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_isMine: Boolean;

        /* internal */ /* var */_canGet: Boolean;

        /* internal */ /* var */_info: EntityInfo;

        /* internal */ /* var */_bossInfo: TBoss;

        /* internal */ /* var */_nameLabel: GTextFiled;

        /* internal */ /* var */_itemsList: ItemsBox;

        /* internal */ /* var */_progressBar: PetProcessBar;

        /* internal */ /* var */_operBtn: TimeButton;

        /* internal */ /* var */_tip: GTextFiled;
    }
